package com.springboot.repository;

import com.springboot.domain.BtEnterprise;
import com.springboot.dto.EnterpriseListDTOTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

//import com.springboot.dto.EnterpriseListDemoDTO;

@Repository
public interface EnterpriseRepository extends JpaRepository<BtEnterprise, String> {

    @Modifying
    @Query("update BtEnterprise be set be.status = '4' where be.id = ?1")
    void logout(String userId);

//    @Query(value = "SELECT  be.id AS id,bf.id AS pictureId FROM bt_enterprise be LEFT JOIN  bt_file bf ON be.id = bf.user_id AND bf.parameter_name='headPicture'  WHERE be.status =?1 ORDER BY ?#{#pageable} ",
//            countQuery = "SELECT COUNT (be.id) FROM bt_enterprise be LEFT JOIN  bt_file bf ON be.id = bf.user_id AND bf.parameter_name='headPicture'  WHERE be.status =?1",
//            nativeQuery = true)
//    Page<EnterpriseListDTOTest> findListByStatus(String status, Pageable pageable);


    Page<BtEnterprise> findByStatus(String status, Pageable pageable);

    @Query("select be from BtEnterprise be, com.springboot.domain.BtUser bu where be.id = bu.userId and bu.userName like concat('%',?1,'%') " +
            " and be.name like concat('%',?2,'%') and be.province like concat('%',?3,'%') and  be.industry like concat('%',?4,'%') and bu.status = '0' and be.status = '2'")
    List<BtEnterprise> findConcatEnterprise(String userName, String name, String province, String industry);

    @Modifying
    @Query("update BtEnterprise be set be.views = ?1 where be.id = ?2 ")
    void addViews(int views, String id);

    @Query("select be from BtEnterprise be where be.name like concat('%',?1,'%') and be.status = '2'")
    List<BtEnterprise> findEnterprise(String name);
}
